package com.jn.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
@Component
public class SendMail {
	public ApplicationContext ctx = null;

	public SendMail() {
		// 获取上下文
		ctx = new ClassPathXmlApplicationContext("applicationContext-mail.xml");
	}

	 public void send(PostVO post) {  
		// 获取JavaMailSender bean
		JavaMailSender sender = (JavaMailSender) ctx.getBean("mailSender");
		SimpleMailMessage mail = new SimpleMailMessage();// <span
															// style="color: #ff0000;">注意SimpleMailMessage只能用来发送text格式的邮件</span>
		try {
			mail.setTo("cuiyl@hollycrm.com");// 接受者
			mail.setFrom("cuiyuliang926@163.com");//发送者,这里还可以另起Email别名，不用和xml里的username一致
			
			mail.setSubject("spring mail test!");// 主题
			mail.setText("springMail的简单发送测试");// 邮件内容
			sender.send(mail);
		} catch (Exception e) {
			e.printStackTrace();

		}
	}
	
	

}
